package com.hf.action;

import javax.servlet.http.HttpSession;

import com.base.bean.User;
import com.hf.listener.MySessionContext;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * Action 访问Servlet API
 * @author Administrator
 *
 */

public class TestSessionAction extends BaseAction{
	private String sessionId;
	private Integer times;	//次数
	private String memo;
	private boolean delSession;
	
	
	
	
	@Override
	public String execute() {
		// System.out.println("session Action Start");
		sessionId=(sessionId==null?"":sessionId);	
		
		this.tip="";
		this.memo="xxxx";
		
		times=((times==null || times==0 )?new Integer(0):times);
		if(this.times>9)
			times=1;
		
		memo=(memo==null?"":memo);
		times=times+1;
		if(sessionId.equals("")){
			this.tip="sessionId为空";
			return SUCCESS;
		}
		
		
		// TODO Auto-generated method stub
		User u=new User(1);
		u.setName("admin");
		
		
		memo="+++"+times.toString();
		HttpSession session=null;
		try{
		session = MySessionContext.getSession(sessionId);
		
		
		
		if(session!=null)
			session.setAttribute("times", MySessionContext.getSessionCounts());
		
		//this.times=(Integer) session.getAttribute("times");
		
		}catch(Exception e){
			this.tip="未找到该sessionId";
		}
		
		
		System.out.println("sessionId:"+ sessionId);	
		System.out.println("memo:"+memo);	
		System.out.println("times:"+times);	
		System.out.println("tip:"+tip);	
		return SUCCESS;
	}




	public String getSessionId() {
		return sessionId;
	}




	public void setSessionId(String sessionId) {
		this.sessionId = sessionId;
	}




	public Integer getTimes() {
		return times;
	}




	public void setTimes(Integer times) {
		this.times = times;
	}




	public String getMemo() {
		return memo;
	}




	public void setMemo(String memo) {
		this.memo = memo;
	}




	public boolean isDelSession() {
		return delSession;
	}




	public void setDelSession(boolean delSession) {
		this.delSession = delSession;
	}
	
	
}
